<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
    <title>配送交接</title>
    <meta name="decorator" content="form"/>
    <html:css name="bootstrap-fileinput" />
    <html:css name="simditor,jqgrid" />
</head>

<body class="white-bg">
		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td  class="width-15 active text-right">
						<label><font color="red">*</font>交接日期:</label>
					</td>
					<td class="width-35">
						<input id="ccZcdMxSimpleHandOverDate" htmlEscape="false" class="form-control layer-date" placeholder="YYYY-MM-DD hh:mm:ss" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss', start: laydate.now(0, 'YYYY-MM-DD hh:mm:ss')})" />
						<label class="Validform_checktip"></label>
					</td>
					<td class="width-15 active text-right"></td>
					<td class="width-35" ></td>
				</tr>
		   </tbody>
		</table>   
	<div class="row">
        <div class="tabs-container">
            <ul class="nav nav-tabs">
            	<li class="active"><a data-toggle="tab" href="#tab_ccZcdMxSimple" aria-expanded="true">装车单明细</a></li>
            </ul>
            <div class="tab-content">
                 <div id="tab_ccZcdMxSimple" class="tab-pane active">
                    <div class="panel-body">
                        <grid:grid id="ccZcdMxSimpleGridId" datas="${zcdMxList}" pageable="false" shrinkToFit="false" >
							<grid:column label="sys.common.opt" name="opt" formatter="button" width="80"/>
							<grid:button title="cc.humiture.title" groupname="opt" function="rowDialogDetail" outclass="btn-primary" url="${adminPath}/cc/device/humiture?sn=\"+row.sbSn+\"&carFlag=\"+row.carFlag+\"&pointone=\"+row.pointone+\"&pointtwo=\"+row.pointtwo+\"&beginDate=\"+row.beginDate+\"&endDate=\"+row.endDate+\"&wendMin=\"+row.wendMin+\"&wendMax=\"+row.wendMax+\"" />
							<grid:column label="装车单号" name="zhuangcdNo"/>
							<grid:column label="单据编号" name="danjNo"/>
							<grid:column label="冷藏箱号" name="boxSn" width="70"/>
							<grid:column label="设备编号" name="sbSn" width="70"/>
							<grid:column label="冷藏车运输" name="carFlag" dict="sf" width="70"/>
							<grid:column label="冷藏车测点1" name="pointone" width="70"/>
							<grid:column label="冷藏车测点2" name="pointtwo" width="70"/>
							<grid:column label="单位名称" name="danwName"/>
							<grid:column label="单位地址" name="address"/>
							<grid:column label="开始时间" name="beginDate"/>
							<grid:column label="结束时间" name="endDate"/>
						</grid:grid>
					</div>
                </div>
            </div>
        </div>
    </div>
<html:js name="bootstrap-fileinput" />
<html:js name="simditor,jqgrid,jqGrid_curdtools,jqGrid_curdtools_inline" />
<script>
	$(document).ready(function () {
	    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
	    	 resizeGrid();
		});
	});
	$(function(){
	   $(window).resize(function(){   
		   resizeGrid();
	   });
	});

	function resizeGrid(){
		 $("#ccZcdMxSimpleGrid").setGridWidth($(window).width()-60);
	}

	/* 父页面点击确定时触发的事件 */
	function confirm(callback) {
		var selectedRows = $("#ccZcdMxSimpleGridIdGrid").jqGrid('getGridParam','selarrrow');
		// 如果没有选择，提示
		if (selectedRows.length == 0) {
			top.layer.alert('请选择进行交接的明细!', {icon: 0, title:'警告'});
			return;
		}
		// 判断交接时间
		if (isNull($("#ccZcdMxSimpleHandOverDate").val())) {
			top.layer.alert('请填写交接时间!', {icon: 0, title:'警告'});
			return;
		}

		// 获取数据
		var zcdNo = $("#ccZcdMxSimpleGridIdGrid").jqGrid('getRowData', selectedRows[0]).zhuangcdNo;
		var rowData = [];
		var danjNos = [];
		for (var i = 0; i < selectedRows.length; i++) {
			rowData = $("#ccZcdMxSimpleGridIdGrid").jqGrid('getRowData', selectedRows[i]);
			if (isNull(rowData.endDate)) {
				danjNos.push(rowData.danjNo);
			}
		}

		if (danjNos.length < 1) {
			top.layer.alert('所选单据均已交接，不可重复交接!', {icon: 0, title:'警告'});
			return;
		}

		// POST请求配送交接
		$.ajax({
			type: "POST",
			url: "${adminPath}/cc/zcd/beforeHandOver",
			data: {
				zcdNo : zcdNo,
				danjNos : danjNos,
				handOverDate : $("#ccZcdMxSimpleHandOverDate").val()
			},
			traditional: true,
			success: function (data) {
				if (data.ret == -2) {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
					return;
				}
				else if (data.ret == 0) {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
					// 最后调用回调函数，关闭对话框
					if (typeof callback == "function") {
						callback();
					}
				}
				else {
					top.layer.open({
						content: data.msg
						, btn: ['确定','取消'],
						yes: function(index, layero){
							$.ajax({
								type: "POST",
								url: "${adminPath}/cc/zcd/handOver",
								data: {
									zcdNo : zcdNo,
									danjNos : danjNos,
									handOverDate : $("#ccZcdMxSimpleHandOverDate").val()
								},
								traditional: true,
								success: function (data) {
									top.layer.alert(data.msg, {icon: 0, title:'提示'});
									if (data.ret == 0) {
										// 最后调用回调函数，关闭对话框
										if (typeof callback == "function") {
											callback();
										}
									}
								}
							});
						},
						cancel: function(index,layero){ //按右上角“X”按钮

						}
					})
				}
			}
		});
	}

</script>
</body>
</html>